def erfen(beichalist,neirong):
    #先排序在再查找
    beichalist.sort()  #从小到大排序，会改变原始列表，stored函数不会改变原始列表
    #索引值
    xiao=0
    da=len(beichalist)-1
    while xiao<=da:
        zhongjian=(xiao+da)//2
        if beichalist[zhongjian]==neirong:
            return zhongjian
        elif beichalist[zhongjian]>neirong:
            da=zhongjian-1
        else:
            xiao=zhongjian+1
    return '没有'

arr=[1,2,3,4,5,6,7,8,9,10,11]
print(erfen(arr,3))
print(erfen(arr,13))

#线性查找
def xianxing(beichalist,neirong):
    for i in range(len(beichalist)):
        if beichalist[i]==neirong:
            return i
    return -1
arr=[1,2,3,4,5,6,7,8,9,10,11]
print(xianxing(arr,12))


def charu(arr):
    for i in range(1,len(arr)):
        key=arr[i]
        j=i-1
        while j>=0 and arr[j]>key:
            arr[j+1]=arr[j]
            j-=1
        arr[j+1]=key
    return arr
